<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生成维修单</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="../css/element-ui.css" />
    <link rel="stylesheet" href="css/index.css">
    <!--[if lt IE 9]>
    <link rel="stylesheet" href="../css/pages/ie8.css"/>
    <script src="../js/common/html5shiv.min.js"></script>
    <script src="../js/common/respond.min.js"></script>
    <script src="../js/common/es5-shim.min.js"></script>
    <![endif]-->
     <script src="js/babel.min.js"></script>
    <script src="../js/common/jquery.min.js"></script>
    <script src="../js/common/vue.js"></script>
    <script src="../js/common/element-ui.js"></script>
    
</head>
<body>
<div id="repair-bill-box">
	<div class="repair-items">
	    <div class="repair-item" :class="{active:selected==1}" @click="edit">
	        <span class="ic-repair ic-edit" ></span><br/><span class="text" >编辑</span>
	    </div>
	    <div class="repair-item" :class="{active:selected==2}" @click="save">
	        <span class="ic-repair ic-save"></span><br/><span class="text" >保存</span>
	    </div>
	    <div class="repair-item" :class="{active:selected==3}" @click="check">
	        <span class="ic-repair ic-check"></span><br/><span class="text" >验收</span>
	    </div>
	    <div class="repair-item"  :class="{active:selected==4}" @click="revocation">
	        <span class="ic-repair ic-revocation"></span><br/><span class="text" >撤销验收</span>
	    </div>
	    <div class="repair-item" :class="{active:selected==5}" @click="cancel" >
	        <span class="ic-repair ic-cancel"></span><br/><span class="text" >作废</span>
	    </div>
	    <div class="repair-item" style="float:right" @click="back">
       	 <span class="ic-repair ic-back"></span>
   		 </div>
	</div>
<div class="container">
    <div class="repair-header">
        <table>
            <tr>
                <td>
                    <div class="wrapper"><span class="text">单据号：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text"  :value="Head.BillSN"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">发票号：</span>
                        <div class="fill"><input class="disabled" :disabled="forbid" type="text" v-model="Head.InvoiceNumber" ></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">验收人：</span>
                        <div class="fill"><input type="text" class="disabled forbid" disabled="disabled" :value="Head.CheckUserName"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">账册名称：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value='Head.GoodsBookName'></div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="wrapper"><span class="text">账户名称：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="Head.DeptAccountName"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">总金额：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="amount.toFixed(2)"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">验收时间：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value='Head.CheckTime'></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">状态：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="Head.StatusStr"></div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="wrapper"><span class="text">科室名称：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="Head.DeptName"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">录入人：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value='Head.InputUserName'></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">登帐人：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="Head.BookinUserName"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"></div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="wrapper"><span class="text">维修商：</span>
                        <div class="fill">
                        	<input class="disabled"  disabled="disabled" type="text" v-model='repairManSelected'  @click="repairMan">
                        	<div class="shadow" :class={show:isShow} ></div>	
                        	<div class="repairMan-wrap" :class={show:isShow} >
                        		<i class="ic-close" @click="close"></i>
                        		<div class="search">
                        			<input placeholder="请输入拼音或名称查询" class="search-input"   v-model="repairManSelected">
                        			<el-button type="primary" round @click="sure">确定</el-button>
                        		</div>
                        		<div class="repairMan-content">
                        			<div class="content">
                        			 <table>
                        			 	<tr>
                        			 		<th>维修商ID</th>
                        			 		<th>维修商</th>
                        			 		<th>拼音码</th>
                        			 	</tr>
                        			 	<tr :class="{active:active==index}" v-if="tableData.length>0" v-for="(v,index) in tableData" @click="checked(v.SupplierName,v.SupplierID)"  @mouseover="mouseover(index)" >
                        			 		<td>{{v.SupplierID}}</td>
                        			 		<td>{{v.SupplierName}}</td>
                        			 		<td>{{v.PyCode}}</td>
                        			 	</tr>
                        			 </table>
                        			</div>
								   
                        		</div>	
                        	</div>	
                        </div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">录入时间：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value="Head.InputTime"></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"><span class="text">登帐时间：</span>
                        <div class="fill"><input class="disabled forbid" disabled="disabled" type="text" :value='Head.BookinTime'></div>
                    </div>
                </td>
                <td>
                    <div class="wrapper"></div>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div class="wrapper"><span class='required'>*</span><span class="text">维修理由：</span>
                        <div class="fill"><input class="disabled" :disabled="forbid" type="text" v-model="Head.RepairReason"></div>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div class="wrapper"><span class="text">审核说明：</span>
                        <div class="fill"><input class="disabled" :disabled="forbid" type="text" v-model="Head.CheckComment"></div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="repair-middle clearfix">
        <div class="aside">
            <h2>维修物品</h2>
            <div class="goods">
                <dl>
                    <dt>{{GoodsDetail.GoodName}}</dt>
                </dl>
            </div>
        </div>
        <div class="content">
            <h2>维修信息</h2>
            <div class="wrap">
                <div class="tab" id="tab">
                    <span class="item" :class="{selected:tabIndex==index}" v-for = "(tabList,index) in tabLists" @click="tab(index)">{{tabList}}</span>
                    <!-- <span class="item">金额信息</span>
                    <span class="item">详细说明</span> -->
                </div>
                <div class="tabCon" id="tabCon">
                    <div class="tab-item " v-show="tabIndex==0">
                        <ul class="item-wrapper">
                            <li class="list">
                                <span>物品名称：</span><input class="disabled forbid" disabled="disabled" type="text" :value="GoodsDetail.GoodName">
                                <span>维修人：</span><input class="disabled" :disabled="forbid" type="text" v-model='GoodsDetail.RepairMan'>
                            </li>
                            <li class="list">
                                <span>批次号：</span><input class="disabled forbid" disabled="disabled" type="text" :value='GoodsDetail.BatchSN'>
                                <span>维修数量：</span><input class="disabled" :disabled="forbid" type="text" v-model="Counts">
                            </li>
                            <li class="list">
                                <span><input type="checkbox" disabled="disabled" :checked="GoodsDetail.HasCard"/>卡片：</span><input class="disabled forbid" disabled="disabled" type="text" :value="GoodsDetail.CardNumber">
                            </li>
                            <li class="list">
                                <span>维修金额：</span><input class="disabled forbid" disabled="disabled" type="text" :value="amount.toFixed(2)">
                                <span>维修时间：</span>
                                <div class="block">
								    <el-date-picker
								      v-model="GoodsDetail.RepairStart"
								      type="datetime"
								      format="yyyy-MM-dd HH:mm:ss"
								      placeholder="选择维修开始时间" :disabled='forbid'>
								    </el-date-picker>
								  </div>
                            </li>
                            <li class="list">
                                <span>联系电话：</span><input class="disabled" :disabled="forbid" type="text" v-model='GoodsDetail.Tel'>
                            </li>
                            <li class="list">
                                <span>维修地点：</span><input class="disabled" :disabled="forbid" type="text" v-model='GoodsDetail.Address'>
                            </li>
                            <li class="list">
                                <span>备注：</span><textarea class="disabled" :disabled="forbid" v-model='GoodsDetail.Comment'></textarea>
                            </li>
                        </ul>
                    </div>
                    <div class="tab-item " v-show="tabIndex==1">
                        <table>
                            <tr style="background-color: #ddd;">
                                <td>维修说明</td>
                                <td>维修方式</td>
                                <td>经费来源</td>
                                <td>金额</td>
                                <td><button @click='addRow(0)' :disabled='forbid'>添加一条</button></td>
                            </tr>
                           <tr class="priceDetail"  v-for="(BillPriceDetail,index) in BillPriceDetails">
                                <td>
                                	<select style="width:100%" :disabled="forbid" v-model="BillPriceDetail.Commet" >
									  <option v-for="v in priceCommit" :value ="v.CommitID" >{{v.CommitName}}</option>
									</select>
                                <td><input class="disabled" value="保外" disabled="disabled" type="text"></td>
                                <td><input class="disabled" :disabled="forbid" type="text" v-model='BillPriceDetail.MoneySource'></td>
                                <td><input class="disabled" :disabled="forbid" type="text" v-model='BillPriceDetail.Pirce'></td>
                           		<td><button @click='del(0,index)' :disabled="forbid">删除</button></td>
                            </tr>
       
                        </table>
                    </div>
                    <div class="tab-item " v-show="tabIndex==2">
                        <table>
                            <tr style="background-color: rgb(221, 221, 221);">
                                <td>物品名称</td>
                                <td>维修说明</td>
                                <td><button @click='addRow(1)' :disabled='forbid'>添加一条</button></td>
                            </tr>
                            <!-- <tr class='commitDetail' v-if='GoodsDetail.BillCommitDetails.length>0' v-for="v in GoodsDetail.BillCommitDetails">
                                <td><input class="disabled" :disabled="forbid" type="text" :value =' v.GoodsName'></td>
                                <td><input class="disabled" :disabled="forbid" type="text" :value =' v.Comment'></td>
                            </tr>
                            <tr class='commitDetail' v-if='GoodsDetail.BillCommitDetails.length==0' >
                                <td><input class="disabled" :disabled="forbid" type="text" ></td>
                                <td><input class="disabled" :disabled="forbid" type="text"></td>
                            </tr> -->
                            <tr class='commitDetail' v-for='(BillCommitDetail,index) in BillCommitDetails' >
                                <td><input class="disabled" :disabled="forbid" type="text" v-model = 'BillCommitDetail.GoodsName'></td>
                                <td><input class="disabled" :disabled="forbid" type="text" v-model = 'BillCommitDetail.Comment'></td>
                            	<td><button @click='del(1,index)' :disabled="forbid">删除</button></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- <div class="repair-footer"></div>-->
</div>
 <div class="popup" :class={popupShow:popup} >
 	 <i class="ic-warning" :class=" isSuccess===0? 'ic-seccess':'' "></i><span class="text">{{notice}}</span>
 </div>	 
</div>
<script src="js/index.js"></script>

<script>
var app = new Vue({
	  el: '#repair-bill-box',
	  data: {
		  isShow:false,
		  isSuccess:0,
		  tabLists:["物品信息","金额信息","详细说明"],
		  tabIndex:0,
		  userID:'',
		  billSN:'',
		  editFlag:false,
		  saveFlag:false,
		  isSave:false,
		  checkFlag:false,
		  revocationFlag:false,
		  cancelFlag:false,
		  amount:0.00,
		  notice:'',
		  popup:false, 
		  selected:0,
		  active:0,
		  BillPriceDetails:[],
		  BillCommitDetails:[],
		  priceCommit:[],
		  forbid:true,
		  list:[],
		  tableData:[],
		  active:null,
		  showNum:0,
		  repairManSelected:'',
		  Counts:1,
		  Head:{
			  "GoodsBookName":"",
			  "GoodsBookID":"",
			  "BillSN":null,
			  "DeptAccountID":"",
			  "DeptID":"",
			  "SupperID":"",
			  "InvoiceNumber":"",
			  "Amount":0,
			  "InputUserID":"",
			  "CheckUserID":"",
			  "BookinUserID":"",
			  "InputTime":"",
			  "CheckTime":"",
			  "BookinTime":"",
			  "RepairReason":"",
			  "CheckComment":"",
			  "InputUserName":"",
			  "CheckUserName":"",
			  "BookinUserName":"",
			  "DeptAccountName":"",
			  "DeptName":"",
			  "SupperName":"",
			  "Status":"",
			  "StatusStr":""
				 
			  },
		GoodsDetail:
			{
				"Address": "",
				"BatchSN": "",
				"BillGoodsDetailSN": "",
				"BillSN": "",
				"CardID": "",
				"CardNumber": "",
				"Comment": "",
				"BillCommitDetails": [],
				"Counts": 1,
				"GoodName": "",
				"GoodsID": "",
				"HasCard": false,
				"ModeStr": " ",
				"Price": 0 ,
				"BillPriceDetails": [],
				"RepairEnd": new Date().format("yyyy-MM-dd hh:mm:ss"),
				"RepairMan": "",
				"RepairStart": null ,
				"Sort": 0,
				"Tel": "",
				"Mode":""
			}
		 
	    
	  },
	 created:function(){
		 var _this=this;
		 this.userID=JSON.parse(localStorage.getItem('currentUser')).Ygid;
		 this.billSN = window.parent.document.getElementById('repair-bill-container').src.split('=')[1]; 
		 this._getBillApi();
		 this.repairManApi();
		 this._GetPriceCommit();
	 },
	　watch:{
	 		Counts:function(curVal,oldVal){
	 			if(!/^[0-9]*$/.test(curVal)){
					  this._popUp("请正确填写维修物品数量!!");
						 return false
			    	}
	 			 this.GoodsDetail.Counts=curVal;
	 		}
		},
	 methods:{
		 edit:function(){
			 if(this.editFlag){
				 return false;
			 }
			this.selected = 1;
			this.forbid = false;
			this.editFlag = true;
			this.saveFlag = true;
		 },
		 save:function(){
			 if(!this.saveFlag){
				 return false;
			 }
			 var _this =this;
			 if(!this.Head.RepairReason){
					this._popUp("请填写维修理由!!"); 
					 return false
				 } 
			 if(!this.repairManSelected){
					this._popUp("请等待客户端处理!!"); 
					 return false
				 } 
			 if(this.GoodsDetail.RepairStart){
				 if(new Date(this.GoodsDetail.RepairStart)>= new Date()){
						this._popUp("维修开始时间不能大于维修结束时间!!");
						 return false
					}
					this.GoodsDetail.RepairStart=new Date(_this.GoodsDetail.RepairStart).format("yyyy-MM-dd hh:mm:ss");
					this.GoodsDetail.RepairEnd=new Date().format("yyyy-MM-dd hh:mm:ss")
				}
			 	var money = 0;
			 	var priceDetails = document.querySelectorAll('.priceDetail');
			 	var len = priceDetails.length;
			 	for(var i=0;i<len;i++){
					var aInput = priceDetails[i].getElementsByTagName('input');
					var oSelect = priceDetails[i].getElementsByTagName('select')[0];
					var selectedIndex = oSelect.selectedIndex;
					 if(!/^([1-9][\d]{0,}|0)(\.[\d]{1,2})?$/.test($.trim($(".priceDetail").eq(i).find('input')[2].value))){
						 _this._popUp("请正确填写金额!!");
						 return false
				    } 
					 money+= this.GoodsDetail.Counts*Number($(".priceDetail").eq(i).find('input')[2].value)
				}    
				this.amount =money;
			 this.getBillPriceDetails();
			 this.getBillCommitDetails();
			 this._saveApi(function(){
				 _this._popUp("保存成功!!",0);
				 _this.saveFlag = false;
				 //_this.isSave=true;
				 _this.checkFlag=true;
				 _this.forbid = false;
				 _this.selected = 2; 
				 _this.showNum++;
			 },function(){
				 _this._popUp("保存失败，请重试!!");
			 });
			 
		 },
		 getBillPriceDetails:function(){
			 var _this = this;
			 this.GoodsDetail.BillPriceDetails.splice(0,_this.GoodsDetail.BillPriceDetails.length);
			 this.BillPriceDetails.forEach(function(item){
					_this.GoodsDetail.BillPriceDetails.push({
							"Commet":item.Commet,
							"ModeStr":item.ModeStr=="保外"?'bw':'',
							"MoneySource":	item.MoneySource,
							"Pirce":item.Pirce,
							"UpdateTime": item.UpdateTime,
							"BillPirceDetailSN": item.BillPirceDetailSN,
							"BillGoodsDetailSN": item.BillGoodsDetailSN,
							"Mode": item.Mode,
							"Sort": item.Sort
					})
				})
		 },
		 getBillCommitDetails:function(){
			 var _this =this;
			 this.GoodsDetail.BillCommitDetails.splice(0,_this.GoodsDetail.BillCommitDetails.length);
			 this.BillCommitDetails.forEach(function(item){
					_this.GoodsDetail.BillCommitDetails.push({
							"GoodsName":item.GoodsName,
							"Comment":	item.Comment,
							"UpdateTime": item.UpdateTime,
							"BillCommitDetailSN": item.BillCommitDetailSN,
							"BillGoodsDetailSN": item.BillGoodsDetailSN,
							"Sort": item.Sort
					})
				})
		 },
		 getAmount:function(){
				 var _this = this;
				 	var money = 0;
				 	var priceDetails = document.querySelectorAll('.priceDetail');
				 	var len = priceDetails.length;
				 	 for(var i=0;i<len;i++){
						var aInput = priceDetails[i].getElementsByTagName('input');
						var oSelect = priceDetails[i].getElementsByTagName('select')[0];
						var selectedIndex = oSelect.selectedIndex;
						 money+= this.GoodsDetail.Counts*Number($(".priceDetail").eq(i).find('input')[2].value)
					}   
					this.amount =money;
		 },
		 _popUp:function(str,code){
			 if(code&&code==0){
				 this.isSuccess==1;
			 }else this.isSuccess==0;
			 var _this = this;
			 this.popup=true;
			 this.notice=str;
			 var timer = setInterval(function(){
				 _this.popup=false;
				 clearInterval(timer);
			 },1000)
		 },
		 check:function(){
			 var _this=this;
			 if(!this.checkFlag){
				 return false;
			 }
			 this.forbid = false;
			 if(!this.GoodsDetail.RepairMan||!this.Counts||!this.GoodsDetail.RepairStart ||!this.GoodsDetail.Tel||!this.GoodsDetail.Address||!this.GoodsDetail.Comment){
					this._popUp("请填写物品信息!!"); 
					 return false
				} 
			 if(!this.GoodsDetail.RepairMan){
					this._popUp("请填写维修人姓名!!"); 
					 return false
			} 
			 if(!/^[0-9]*$/.test(this.Counts)){
				  this._popUp("请正确填写维修物品数量!!");
					 return false
		    	}
			 if(!this.GoodsDetail.RepairStart){
					this._popUp("请填写维修开始时间!!"); 
					 return false
				}
			if(new Date(this.GoodsDetail.RepairStart)>= new Date()){
				this._popUp("维修开始时间不能大于维修结束时间!!");
				 return false
			}
			
			 if(!/^[0-9]*$/.test(this.GoodsDetail.Tel)){
				 this._popUp("请正确填写手机号码!!");
				 return false
		    } 
			var money = 0;
		 	var priceDetails = document.querySelectorAll('.priceDetail');
		 	var len = priceDetails.length;
		 	for(var i=0;i<len;i++){
				var aInput = priceDetails[i].getElementsByTagName('input');
				var oSelect = priceDetails[i].getElementsByTagName('select')[0];
				var selectedIndex = oSelect.selectedIndex;
				if(selectedIndex<0||!aInput[1].value||!aInput[2].value){
					 _this._popUp("请填写金额信息!!");
					 return false
				} 
				 if(!/^([1-9][\d]{0,}|0)(\.[\d]{1,2})?$/.test($.trim($(".priceDetail").eq(i).find('input')[2].value))){
					 _this._popUp("请正确填写金额!!");
					 return false
			    } 
				 money+= this.GoodsDetail.Counts*Number($(".priceDetail").eq(i).find('input')[2].value)
			}    
			this.amount =money;
			var commitDetail= document.querySelectorAll('.commitDetail');
			for(var i=0;i<commitDetail.length;i++){
				var aInput = commitDetail[i].getElementsByTagName('input');
				if(!aInput[0].value||!aInput[1].value){
					 _this._popUp("请填写详细说明!!");
					 return false
				} 
			}    
			this.getBillPriceDetails(); 
			this.GoodsDetail.Counts=this.Counts;
			this.getBillCommitDetails();
			this.GoodsDetail.RepairStart=new Date(_this.GoodsDetail.RepairStart).format("yyyy-MM-dd hh:mm:ss");
			this.GoodsDetail.RepairEnd=new Date().format("yyyy-MM-dd hh:mm:ss");
				if(this.showNum>1){
					 this._checkBillApi(function(){
						 _this._getBillApi();
						 _this.forbid = true;
						 _this.checkFlag = false;
						 _this.saveFlag=false;
						 _this.revocationFlag = true;
						 _this.selected = 3;
						 _this.showNum = 0;
					 });
				}else{
					 _this._popUp("请再次保存!!");
					 _this.saveFlag=true;
					 return false
				}
		 },
		 revocation:function(){
			 var _this = this;
			 if( !this.revocationFlag ){
				 return false;
			 }
			 this._undoCheckBillApi(function(){
				 _this._getBillApi();
				 _this.revocationFlag  = false;
				 _this.editFlag = false;
				 _this.checkFlag=false;
				 _this.saveFlag = false;
				 _this.selected = 4;
			 });
		 },
		 cancel:function(){
			 var _this = this;
			 if(this.cancelFlag){
				 return false;
			 }
			var con = confirm('确实要作废吗?');
			 if(!con){
				 return false
			 }
			 this._nullifyBillApi(function(){
				 _this._getBillApi();
				 _this.editFlag = true;
				 _this.checkFlag=true;
				 _this.saveFlag = true;
				 _this.revocationFlag= true;
				 _this.cancelFlag = true;
				 _this.selected = 5;
			 });
			 
			
		 },
		 back:function(){
			 $(window.parent.document).find('#repair-bill-container').remove();
		 },
		 tab:function(index){
			 this.tabIndex=index;
		 },
		 mouseover:function(index){
			this.active = index;
		 },
		 checked:function(name,id){
			 this.repairManSelected=name;
			 this.Head.SupperID = id
			 this.isShow=false;
		 },
		 filters:function(){
			 for(var i=0;i<this.list.length;i++){
                 if(this.list[i].SupplierName.indexOf(this.repairManSelected)!=-1||this.list[i].PyCode.indexOf(this.repairManSelected)!=-1){
                	 this.tableData.push(this.list[i])
                 }
             }
			 
		 },
		 close:function(){
			 this.isShow=false;
		 },
		 sure:function(){
			 var _this= this;
			 if(_this.repairManSelected == ''){
				 return false;
			 }
			 this.tableData=[];
			 for(var i=0;i<_this.list.length;i++){
                 if(_this.list[i].SupplierName.indexOf(_this.repairManSelected)!=-1||_this.list[i].PyCode.indexOf(_this.repairManSelected)!=-1){
                	 _this.tableData.push(_this.list[i])
                 }
             }
		 },
		 del:function(code,index){
			 /* if(this.saveFlag){
				 return false;
			 } */
			 var _this = this;
			 if(code===0){
				 var len =  document.querySelectorAll('.priceDetail').length;
				 if(len<=1){
					 _this._popUp("必须填写一条!!");
					 return false
				 }
				this.BillPriceDetails.splice(index,1);
			 }else if(code===1){
				 var len =  document.querySelectorAll('.commitDetail').length;
				 if(len<=1){
					 _this._popUp("必须填写一条!!");
					 return false
				 }
				this.BillCommitDetails.splice(index,1);
			 }
			
			
		 },
		 addRow:function(code){
			var _this = this;
			if(code===0){
				var len =  document.querySelectorAll('.priceDetail').length;
				var priceDetail =  document.querySelectorAll('.priceDetail')[len-1];
				var aInput = priceDetail.getElementsByTagName("input");
				for(var i=0, aInputLen = aInput.length;i<aInputLen;i++){
					if(aInput[i].value==""){
						 _this._popUp("请先填写该条!!");
						 return false
					}
				};
				this.BillPriceDetails.push({
					"Commet":'',
					"ModeStr":'保外',
					"MoneySource":null,
					"Pirce":0.00,
					"UpdateTime": null,
					"BillPirceDetailSN": null,
					"BillGoodsDetailSN": null,
					"Mode": {},
					"Sort": null
				});
			}else if(code===1){
				var len =  document.querySelectorAll('.commitDetail').length;
				var commitDetail =  document.querySelectorAll('.commitDetail')[len-1];
				var aInput = commitDetail.getElementsByTagName("input");
				for(var i=0, aInputLen = aInput.length;i<aInputLen;i++){
					if(aInput[i].value==""){
						 _this._popUp("请先填写该条!!");
						 return false
					}
				};
				this.BillCommitDetails.push({
					"GoodsName":'',
					"Comment":'',
					"UpdateTime": null,
					"BillCommitDetailSN": null,
					"BillGoodsDetailSN": null,
					"Sort": null	
					})
			}
			
		 },
		 _nullifyBillApi:function(cb){
			 var parms = {
		      		  className: 'RepairManager',
		              method: 'NullifyBill',
		              userID:this.userID,
					  billSN:this.billSN
		    	  }
			 this._fetch(parms,cb);
		 },
		 _undoCheckBillApi:function(cb){
			 var parms = {
		      		  className: 'RepairManager',
		              method: 'UndoCheckBill',
		              userID:this.userID,
					  billSN:this.billSN
		    	  }
			 this._fetch(parms,cb);
		 },
		 _checkBillApi:function(cb){
			 var parms = {
		      		  className: 'RepairManager',
		              method: 'CheckBill',
		              userID:this.userID,
					  billSN:this.billSN
		    	  }
			 this._fetch(parms,cb);
		 },
		 _getBillApi:function(){
			 var that = this;
		       	var parms = {
		      		  className: 'RepairManager',
		              method: 'GetBill',
		              billSN:this.billSN
		    	  }
		       	this._fetch(parms,function(result){
		       		var Head = result.Head;
					 var GoodsDetails = result.GoodsDetails;
					 that.amount = Head.Amount;
					 if(Head.StatusStr=="ys"){
						 that.editFlag=true;
						 that.saveFlag=false;
						 that.checkFlag=false;
					 	that.revocationFlag=true;
					 }else if(Head.StatusStr=="zf"||Head.StatusStr=="dz"){
						 that.editFlag=true;
						 that.saveFlag=false;
						 that.checkFlag=false;
					 	that.revocationFlag=false;
					 	that.cancelFlag=true;
					 };
					  var PDLen= GoodsDetails[0].PriceDetails.length;
					  if(PDLen>0){
						  GoodsDetails[0].PriceDetails.forEach(function(item,index){
							  that.BillPriceDetails[index]={
									  "Commet":item.Commet,
										"ModeStr":item.ModeStr=='bw'?'保外':'',
										"MoneySource":item.MoneySource,
										"Pirce":item.Pirce,
										"UpdateTime": item.UpdateTime,
										"BillPirceDetailSN": item.BillPirceDetailSN,
										"BillGoodsDetailSN": item.BillGoodsDetailSN,
										"Mode": {},
										"Sort": item.Sort	  
							  } 
						  })
						  
					  }else that.BillPriceDetails.push({
						  "Commet":'',
							"ModeStr":'保外',
							"MoneySource":null,
							"Pirce":0.00,
							"UpdateTime": null,
							"BillPirceDetailSN": null,
							"BillGoodsDetailSN": null,
							"Mode": {},
							"Sort": null
					  });
					  var BCLen= GoodsDetails[0].CommitDetails.length;
					  if(BCLen>0){
						  GoodsDetails[0].CommitDetails.forEach(function(item,index){
							  that.BillCommitDetails[index]={
									  "GoodsName":item.GoodsName,
										"Comment":	item.Comment,
										"UpdateTime": item.UpdateTime,
										"BillCommitDetailSN": item.BillCommitDetailSN,
										"BillGoodsDetailSN": item.BillGoodsDetailSN,
										"Sort": item.Sort	  
							  } 
						  })
						  
					  } else that.BillCommitDetails.push({
							"GoodsName":'',
							"Comment":'',
							"UpdateTime": null,
							"BillCommitDetailSN": null,
							"BillGoodsDetailSN": null,
							"Sort": null	
							})
					that.repairManSelected = Head.SupperName;		
					 that.Head={
						  "GoodsBookName":Head.GoodsBookName,
						  "GoodsBookID":Head.GoodsBookID,
						  "BillSN":Head.BillSN,
						  "DeptAccountID":Head.DeptAccountID,
						  "DeptID":Head.DeptID,
						  "SupperID":Head.SupperID,
						  "InvoiceNumber":Head.InvoiceNumber,
						  "Amount":Head.Amount,
						  "InputUserID":Head.InputUserID,
						  "CheckUserID":Head.CheckUserID,
						  "BookinUserID":Head.BookinUserID,
						  "InputTime":!Head.InputTime?Head.InputTime:Head.InputTime.split('.')[0],
						  "CheckTime":!Head.CheckTime?Head.CheckTime:Head.CheckTime.split('.')[0],
						  "BookinTime":!Head.BookinTime?Head.BookinTime:Head.BookinTime.split('.')[0],
						  "RepairReason":Head.RepairReason,
						  "CheckComment":Head.CheckComment,
						  "InputUserName":Head.InputUserName,
						  "CheckUserName":Head.CheckUserName,
						  "BookinUserName":Head.BookinUserName,
						  "DeptAccountName":Head.DeptAccountName,
						  "DeptName":Head.DeptName,
						  "SupperName":Head.SupperName,
						  "Status":Head.Status,
						  "StatusStr":Head.StatusStr=='lr'?'录入':Head.StatusStr=='ys'?'验收':Head.StatusStr=='zf'?'作废':Head.StatusStr=='dz'?'登账':''
						  };
						  that.GoodsDetail={
								"CardNumber":GoodsDetails[0].CardNumber,
								"GoodName":GoodsDetails[0].GoodName,
								"BillCommitDetails":GoodsDetails[0].CommitDetails,
								"BillPriceDetails":GoodsDetails[0].PriceDetails,
								"BillGoodsDetailSN":GoodsDetails[0].BillGoodsDetailSN,
								"BillSN":GoodsDetails[0].BillSN,
								"GoodsID":GoodsDetails[0].GoodsID,
								"BatchSN":GoodsDetails[0].BatchSN,
								"RepairMan":GoodsDetails[0].RepairMan,
								"Tel":GoodsDetails[0].Tel,
								"Address":GoodsDetails[0].Address,
								"Counts":GoodsDetails[0].Counts,
								"Price":GoodsDetails[0].Price,
								"HasCard":GoodsDetails[0].HasCard,
								"CardID":GoodsDetails[0].CardID,
								"RepairStart":GoodsDetails[0].RepairStart,
								"RepairEnd":GoodsDetails[0].RepairEnd,
								"Comment":GoodsDetails[0].Comment,
								"Sort":GoodsDetails[0].Sort,
								"ModeStr":GoodsDetails[0].ModeStr,
								"Mode":GoodsDetails[0].Mode
					 }
		       	})
		 },
		 _saveApi:function(cb,failure){
			 var _this = this;
			 var StatusStr = this.Head.StatusStr=="录入"?'lr':this.Head.StatusStr=="验收"?'ys':this.Head.StatusStr=="登账"?'dz':this.Head.StatusStr=="作废"?'zf':'';
			 var repairBill = {
					 "Head": {
							"GoodsBookID": this.Head.GoodsBookID,
							"BillSN": this.Head.BillSN,
							"DeptAccountID": this.Head.DeptAccountID,
							"DeptID": this.Head.DeptID,
							"SupperID": this.Head.SupperID,
							"InvoiceNumber": this.Head.InvoiceNumber,
							"Amount":this.amount,
							"InputUserID": this.Head.InputUserID,
							"CheckUserID": this.Head.CheckUserID,
							"BookinUserID": this.Head.BookinUserID,
							"InputTime": this.Head.InputTime,
							"CheckTime": this.Head.CheckTime,
							"BookinTime": this.Head.BookinTime,
							"RepairReason": this.Head.RepairReason,
							"CheckComment": this.Head.CheckComment,
							"SupperID":this.Head.SupperID,
							"Status": this.Head.Status,
							"StatusStr": StatusStr
						},
						"GoodsDetails": [{
							"BillPriceDetails": this.GoodsDetail.BillPriceDetails,
							"BillCommitDetails": this.GoodsDetail.BillCommitDetails,
							"BillGoodsDetailSN": this.GoodsDetail.BillGoodsDetailSN,
							"BillSN": this.GoodsDetail.BillSN,
							"GoodsID": this.GoodsDetail.GoodsID,
							"BatchSN": this.GoodsDetail.BatchSN,
							"Mode": this.GoodsDetail.Mode,
							"ModeStr": this.GoodsDetail.ModeStr,
							"RepairMan": this.GoodsDetail.RepairMan,
							"Tel": this.GoodsDetail.Tel,
							"Address": this.GoodsDetail.Address,
							"Counts":this.GoodsDetail.Counts,
							"Price": this.amount,
							"HasCard": this.GoodsDetail.HasCard,
							"CardID": this.GoodsDetail.CardID,
							"RepairStart": this.GoodsDetail.RepairStart,
							"RepairEnd": this.GoodsDetail.RepairEnd,
							"Comment": this.GoodsDetail.Comment,
							"Sort": this.GoodsDetail.Sort
						}]
					} 
			 var parms = {
			      		  className: 'RepairManager',
			              method: 'ModifyBill',
			              repairBill:JSON.stringify(repairBill),
			              userID:this.userID
			    	  }
			 this._fetch(parms,cb,failure);
		 },
		 _fetch:function(parms,cb,failure){
			 $.ajax({
				  type: 'POST',
				  url: getRootPath()+'/api/sendPostRequest' ,
				  headers: {
					  'Accept': 'application/json',
				      'Content-Type': 'application/json'
			        },
				  data: JSON.stringify(parms),
				  success: function(res){
					  if(res.issuccess==0){
						 var result = JSON.parse(res.result);
						 cb&&cb(result)
					  }else {
						  failure&&failure();
					  }
				},
				error:function(err){
					alert(err)
				}
			 });	    
		 },
		_GetPriceCommit:function(){
			var _this = this;
			var parms= {
					className: 'RepairManager',
		   	        method: 'GetPriceCommit'
			}
			 this._fetch(parms,function(result){
				 _this.priceCommit = result;
				// _this.BillPriceDetails.push(_this.priceCommit);
			 })
		},
		repairMan:function(){
			this.isShow=true;
		},
		 repairManApi:function(){
			 var _this = this;
			 //var condition = {"ColumnName":"CardID", "Oper":"Equal", "Value":this.GoodsDetail.CardID,"Type":"String"};
				
			 var condition = {"Conditions":[{"ColumnName":"PyCode","FullString":null,"Oper":"Like","Value":"%%","Type":"String"},{"ColumnName":"SupplierName","FullString":null,"Oper":"Like","Value":"%%","Type":"String"}],"Type":"OR"}

			 var parms = {
			      		  className: 'SupplierManager',
			              method: 'GetSuppliers',
			              condition:JSON.stringify(condition)
			    	  }
			 this._fetch(parms,function(result){
				 _this.list =  result;
				/*  result.forEach(function(item){
					 if(item.SupplierID==_this.Head.SupperID){
						 _this.repairManSelected = item.SupplierName
					 }
				 }) */
				 for(var i=0;i<100;i++){
					 //_this.list.push(result[i]) ;
					 _this.tableData.push(result[i])
					 } 
			 })
			}
	 }
	})
</script>

</body>
</html>